const gulp = require("gulp");
var path = require('path');
const plumber = require("gulp-plumber");
const pug = require("gulp-pug");
const rename = require("gulp-rename");

var ROOT_PATH = path.resolve(__dirname, 'src/main/resources/static');
var SRC_PATH = path.resolve(ROOT_PATH, 'src');
var JSP_PATH = path.resolve(__dirname,'src/main/webapp/WEB-INF/jsp');

gulp.task("template", () => {
    const rev = `?${new Date().getTime().toString()}`;
    return gulp.src([path.resolve(SRC_PATH,'**/*.pug'),'!'+path.resolve(SRC_PATH,'global/**/*')])
        .pipe(plumber())
        .pipe(pug())
        .pipe(rename((filePath) => {
            filePath.dirname='';
            filePath.extname = ".jsp";
        }))
        .pipe(gulp.dest(JSP_PATH))
});

gulp.task("watch", ['template'], () => {
    gulp.watch([path.resolve(SRC_PATH,'**/*.pug'),'!'+path.resolve(SRC_PATH,'global/**/*')], ["template"]);
});

